<!--参保账单-->
<template>
	<el-card>
		<el-form :inline="true" :model="state.queryForm" @keyup.enter="getDataList()">
			<el-form-item class="form-button-right">
				<el-button v-auth="'attendance:shift:save'" type="primary" @click="addOrUpdateHandle()">新增账单</el-button>
			</el-form-item>

			<el-form-item label="选择年份">
				<el-tree-select
					v-model="state.queryForm.carTypeId"
					:data="queryList"
					value-key="id"
					check-strictly
					clearable
					:render-after-expand="false"
					:props="{ value: 'id', label: 'name', children: 'children' }"
					style="width: 100%"
				/>
			</el-form-item>
		</el-form>

		<div class="card" :key="index" v-for="(item, index) of defData">
			<el-card>
				<h1>{{ item.title }}</h1>
				<el-row>
					<el-col :span="3" class="left-and-centre">
						<h1>合计金额</h1>
						<div>
							<span>{{ item.zhouqi }}</span>
						</div>
					</el-col>

					<el-col :span="1">
						<el-divider direction="vertical" style="height: 100%"></el-divider>
					</el-col>

					<el-col :span="5" class="left-and-centre">
						<h1>参保金额</h1>
						<el-statistic :value="item.jihua"> </el-statistic>
					</el-col>
					<el-col :span="5" class="left-and-centre">
						<h1>个人缴纳合计</h1>
						<el-statistic :value="item.jihua"> </el-statistic>
					</el-col>
					<el-col :span="5" class="left-and-centre">
						<h1>公司缴纳合计</h1>
						<el-statistic :value="item.jihua"> </el-statistic>
					</el-col>

					<el-col :span="3" class="right">
						<el-button v-auth="'module:assetStorage:update'" type="primary" link @click="addOrUpdateHandle(item.id)">查看详情</el-button>
						<el-button v-auth="'module:assetStorage:delete'" type="primary" link @click="deleteBatchHandle(item.id)">设置</el-button>
						<el-button v-auth="'module:assetStorage:delete'" type="primary" link @click="deleteBatchHandle(item.id)">终止考核</el-button>
					</el-col>
				</el-row>
			</el-card>
		</div>

		<el-pagination
			:current-page="state.page"
			:page-sizes="state.pageSizes"
			:page-size="state.limit"
			:total="state.total"
			layout="total, sizes, prev, pager, next, jumper"
			@size-change="sizeChangeHandle"
			@current-change="currentChangeHandle"
		>
		</el-pagination>

	</el-card>
</template>

<script setup lang="ts" name="StaffStaffIndex">
import { useCrud } from '@/hooks'
import { Ref, reactive, ref } from 'vue'
import { IHooksOptions } from '@/hooks/interface'

import { findAll } from '@/api/nb/organization/position'
import { findListByDictId } from '@/api/nb/business/dictionaries_subset'
import { findAll as findJobLevel } from '@/api/nb/organization/position/level'
import { findAllApi } from '@/api/nb/organization/workplace'

const queryList = ref()
const state: IHooksOptions = reactive({
	dataListUrl: '/nb/staff/page',
	deleteUrl: '/nb/staff',
	queryForm: {}
})

const defData=ref()
const addOrUpdateRef = ref()
const addOrUpdateHandle = (id?: number) => {
	addOrUpdateRef.value.init(id)
}

// 获取职位
const positionList = ref()
const getPosition = () => {
	return findAll().then(res => {
		positionList.value = res.data
	})
}
getPosition()

// 获取职务
const ziWuList = ref()
const getDictList = (code: String, list: Ref) => {
	findListByDictId({ params: { code: code } }).then(res => {
		list.value = res.data
	})
}
getDictList('ZhiWu', ziWuList)

// 获取 所属职级
const jobLevelList = ref()
const getJobLevelList = () => {
	return findJobLevel().then(res => {
		jobLevelList.value = res.data
	})
}
getJobLevelList()

// 获取 工作地点
const workplaceList = ref()
const getWorkplace = () => {
	return findAllApi().then(res => {
		workplaceList.value = res.data
	})
}
getWorkplace()

const { getDataList, selectionChangeHandle, sizeChangeHandle, currentChangeHandle, deleteBatchHandle } = useCrud(state)
</script>
